package io;


import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.util.Progressable;

public class FileCopyWithProgress {
	public static void main(String[] args) throws Exception {
 		String localSrc =  "E:/workspace_personal/hadoop-demo/src/test/java/URLCat.java";// args[0];
		String dst =  "hdfs://node1:9000/user/hadoop/URLCat.java";// args[1];
		
		InputStream in = new BufferedInputStream(new FileInputStream(localSrc));
		Configuration conf = new Configuration();
 		//conf.set("hadoop.web.ugi", "hadoop,hadoop,hadoop");
		FileSystem fs = FileSystem.get(URI.create(dst), conf); //获得文件系统
		OutputStream out = fs.create(new Path(dst), new Progressable() {
			@Override
			public void progress() {
				System.out.println(".");
			}
		});
		IOUtils.copyBytes(in, out, conf);
		IOUtils.closeStream(in);
		IOUtils.closeStream(out);
	}
}
